
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <base href="${pageContext.request.contextPath}/">
    <meta charset="utf-8">
    <title>找回密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="static/js/layui/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="static/css/layui/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>


<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>找回密码</legend>
</fieldset>

<form class="layui-form" action="" lay-filter="example">


    <div class="layui-form-item">
        <label class="layui-form-label">姓名:</label>
        <div class="layui-input-block">
            <input type="text"  name="name" id="name" lay-verify="username" autocomplete="off" placeholder="请输入姓名
" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">学号/职工号:</label>
        <div class="layui-input-block">
            <input type="number"  name="sid" id="sid" lay-verify="stuid"  autocomplete="off"  placeholder="请输入学号/职工号
" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">手机号:</label>
        <div class="layui-input-block">
            <input type="number" name="phoneid" id="phoneid" placeholder="请输入手机号码" autocomplete="off" class="layui-input" lay-verify="required|phone">
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <%--            <button type="button" class="layui-btn layui-btn-normal" id="LAY-component-form-setval">赋值</button>--%>
            <%--            <button type="button" class="layui-btn layui-btn-normal" id="LAY-component-form-getval">取值</button>--%>
            <button type="submit" class="layui-btn" lay-submit lay-filter="saveBtn">立即找回</button>
            <button type="reset" class="layui-btn" >重置</button>
        </div>
    </div>
</form>

<script src="static/js/layui/layui-v2.6.3/layui.js" charset="utf-8"></script>

<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate,
            $ = layui.jquery;

        //监听提交
        form.on('submit(saveBtn)', function(data){

        let pid =  $("#phoneid").val();
        let sid =  $("#sid").val();
        var name = $("#name").val();
            $.ajax({
                type:"post",
                url:"login/retrieve?pid="+pid+"&&sid="+sid+"&&username="+name,
                datatype:"json",
                success:function (json){
                    if (json.statusCode==200){
                        console.log(json);
                        var index = layer.alert("你的密码为:"+json.forwardUrl, {
                            title: '找回密码'
                        }, function () {
                            // 关闭弹出层
                            layer.close(index);
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                            //局部刷新
                            parent.layui.table.reload("munu-table",{where:{page:1}});

                        });
                    }else if (json.statusCode==300){
                        layer.msg(json.message);
                    }else if (json.statusCode==350)
                        layer.msg(json.message);
                }
            });
            return false;
        });



        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            username: function(value, item){ //value：表单的值、item：表单的DOM对象
                if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
                    return '用户名不能有特殊字符';
                }
                if(/(^\_)|(\__)|(\_+$)/.test(value)){
                    return '用户名首尾不能出现下划线\'_\'';
                }
                if(/^\d+\d+\d$/.test(value)){
                    return '用户名不能全为数字';
                }
                if (value.length>5){
                    return '用户名不能大于5';
                }
                //如果不想自动弹出默认提示框，可以直接返回 true，这时你可以通过其他任意方式提示（v2.5.7 新增）
                if(value === 'xxx'){
                    alert('用户名不能为敏感词');
                    return true;
                }
            }
            ,pass: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
            ,stuid:[
                /^2020(\d{8})+$/,
                '学号必须以2020开头,并且为12位'
            ]
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });


        // //表单赋值
        // layui.$('#LAY-component-form-setval').on('click', function(){
        //     form.val('example', {
        //         "username": "贤心" // "name": "value"
        //         ,"password": "123456"
        //         ,"interest": 1
        //         ,"like[write]": true //复选框选中状态
        //         ,"close": true //开关状态
        //         ,"sex": "女"
        //         ,"desc": "我爱 layui"
        //     });
        // });

        // //表单取值
        // layui.$('#LAY-component-form-getval').on('click', function(){
        //     var data = form.val('example');
        //     alert(JSON.stringify(data));
        // });


    });
</script>

</script>
</body>
</html>
